package main.test
import org.apache.spark.graphx.Graph
import org.apache.spark.sql.{Row, SparkSession}
import org.graphframes.{GraphFrame, examples}
object test2 {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder()
      .appName(this.getClass.getName)
      .master("local[*]")
      .getOrCreate()

//    examples.Graphs.friends
//    tuple.productIterator.toArray
    val g: GraphFrame = examples.Graphs.friends  // get example graph

    // Convert to GraphX
    val gx: Graph[Row, Row] = g.toGraphX

    // Convert back to GraphFrame.
    // Note that the schema is changed because of constraints in the GraphX API.
    val g2: GraphFrame = GraphFrame.fromGraphX(gx)
//    val value = spark.sparkContext.broadcast(g2)
//    for (i <- spark.sparkContext.parallelize(Array(1,2,3))) {
//      value.value.cache()
//    }
//


    //
//    val g: GraphFrame = examples.Graphs.friends  // get example graph
//
//    // We will use AggregateMessages utilities later, so name it "AM" for short.
//    val AM = AggregateMessages
//
//    // For each user, sum the ages of the adjacent users.
//    val msgToSrc = AM.dst("age")
//    val msgToDst = AM.src("age")
//    val agg = { g.aggregateMessages
//      .sendToSrc(msgToSrc)  // send destination user's age to source
//      .sendToDst(msgToDst)  // send source user's age to destination
//      .agg( AM.msg ) } // sum up ages, stored in AM.msg column
//    agg.show()

  }

}
